package com.huawei.spare.part.replace.rx;

import io.reactivex.Observable;
import io.reactivex.ObservableSource;

import java.util.concurrent.Callable;

public class Complete {

    public static void main(String[] args) {
//        Observable.create(new ObservableOnSubscribe<Boolean>() {
//            @Override
//            public void subscribe(ObservableEmitter<Boolean> emitter) throws Exception {
//                emitter.onNext(true);
//                throw new RuntimeException("error");
//            }
//        }).doOnError((e)-> {
//            System.out.println("error");
//        }).doOnComplete(()->{
//            System.out.println("complete");
//        }).subscribe((e)-> {
//            System.out.println(e);
//        });


        Observable.defer(new Callable<ObservableSource<Boolean>>() {
            @Override
            public ObservableSource<Boolean> call() throws Exception {
//                throw new RuntimeException("error");
                return Observable.error(new RuntimeException("error"));
//                return Observable.just(true);
            }
        }).doFinally(()-> {
            System.out.println("final");
        }).doOnNext((e) -> {
            System.out.println("next");
        }).doOnComplete(() -> {
            System.out.println("complete");
        }).subscribe((result) -> {
            System.out.println(result);
        }, (e) -> {
            System.out.println("error");
        });
    }
}
